package cn.com.topchoice.mobile.library.util;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import cn.com.topchoice.mobile.library.BaseApplication;

public class DisplayUtil {

	/**
	 * Convert the dip to the pixel
	 * 
	 * @param dpValue
	 * @return
	 */
	public static int dipToPixel(float dpValue) {
		float scale = BaseApplication.getInstance().getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}

	/**
	 * Convert the pixel to the dip
	 * @param pxValue
	 * @return
	 */
	public static int pixelToDip(float pxValue) {
		float scale = BaseApplication.getInstance().getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}
	
	/**
	 * Get display metrics
	 * 
	 * @return
	 */
	public static DisplayMetrics getDisplayMetrics() {
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager wm = (WindowManager) BaseApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
		wm.getDefaultDisplay().getMetrics(dm);
		return dm;
	}
    public static int getDensityDpi(){
        return BaseApplication.getInstance().getResources().getDisplayMetrics().densityDpi;
    }
    /**
     * Get the screen height
     * 
     * @return
     */
    public static int getScreenHeight() {
    	return BaseApplication.getInstance().getResources().getDisplayMetrics().heightPixels;
    }
    
    /**
     * Get the screen width
     * 
     * @return
     */
    public static int getScreenWidth() {
    	return BaseApplication.getInstance().getResources().getDisplayMetrics().widthPixels;
    }	
}